package com.dd.cloud.user.controller;

import com.dd.cloud.common.vo.LngLatInfoVo;
import com.dd.cloud.common.vo.WeatherInfoVo;
import com.dd.cloud.user.service.common.ICommonService;
import com.dd.cloud.user.service.doctor.IDoctorDetailService;
import com.dd.cloud.user.service.pres.IPresPrescriptionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotBlank;

/**
 * @author Lx
 * @version 1.0
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/common")
public class CommonController {
    @Autowired
    private ICommonService commonService;
    @Autowired
    private IDoctorDetailService doctorDetailService;
    @Autowired
    private IPresPrescriptionService presPrescriptionService;

    /**
     * 生成图形验证码
     *
     * @param response
     * @param key
     * @return
     */
    @GetMapping("/create/image/code")
    public ResponseEntity<Void> createImageCode(HttpServletResponse response, @NotBlank(message = "键值不能为空") String key) {
        commonService.createImageCode(response, key);
        return ResponseEntity.ok().build();
    }

    /**
     * 验证图形验证码
     *
     * @param key
     * @param code
     * @return
     */
    @PostMapping("/verify/image/code")
    public ResponseEntity<Boolean> verifyImageCode(@NotBlank(message = "键值不能为空") String key,
                                                   @NotBlank(message = "验证码不能为空") String code) {
        Boolean res = commonService.verifyImageCode(key, code);
        return ResponseEntity.ok(res);
    }

    /**
     * 根据地址获取经纬度
     *
     * @param addr
     * @return
     */
    @GetMapping("/addr/lng/lat")
    public ResponseEntity<LngLatInfoVo> geocodingUrl(@NotBlank(message = "地址不能为空") String addr) {
        LngLatInfoVo res = commonService.geocodingUrl(addr);
        return ResponseEntity.ok(res);
    }

    /**
     * 查询天气信息 不传任何参数 默认当前网络ip
     *
     * @param province 省份(搭配城市使用/防止城市重名传入)
     * @param city     城市(和ip二选一)
     * @param ip       ip地址(和城市二选一)
     * @param request
     * @return
     */
    @GetMapping("/weather/query")
    public ResponseEntity<WeatherInfoVo> getWeatherInfo(String province, String city, String ip, HttpServletRequest request) {
        WeatherInfoVo res = commonService.getWeatherInfo(province, city, ip, request);
        return ResponseEntity.ok(res);
    }

    /**
     * 通过gpt获取症状的口语化描述
     *
     * @param
     */
    @PostMapping("/gpt/symptom/list")
    public ResponseEntity<Void> getSymptomInfoFromGpt(HttpServletRequest request) {
        commonService.getSymptomInfoFromGpt(request);
        return ResponseEntity.ok().build();
    }

    /**
     * 通过gpt获取症状的口语化描述
     *
     * @param
     */
    @PostMapping("/supervise/doc")
    public ResponseEntity<Void> superviseDoc(HttpServletRequest request) {
        doctorDetailService.sendDocDataToSupervise();
        return ResponseEntity.ok().build();
    }

    /**
     * 通过gpt获取症状的口语化描述
     *
     * @param
     */
    @PostMapping("/supervise/pres")
    public ResponseEntity<Void> supervisePres(HttpServletRequest request) {
        presPrescriptionService.sendDDataToSupervise();
        return ResponseEntity.ok().build();
    }
}
